package flexbars.controls
{

import flash.errors.IllegalOperationError;

//--------------------------------------
//  Events
//--------------------------------------

//--------------------------------------
//  Styles
//--------------------------------------

//--------------------------------------
//  Excluded APIs
//--------------------------------------

//--------------------------------------
//  Other metadata
//--------------------------------------

public class Code25 extends LinearBarcode
{
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	public function Code25()
	{
		super();
	}
	
	//--------------------------------------------------------------------------
	//
	//  Constants
	//
	//--------------------------------------------------------------------------
	
	protected static const DIGIT_ENCODING:Array = 
	[
		[1, 1, 2, 2, 1],
		[2, 1, 1, 1, 2],
		[1, 2, 1, 1, 2],
		[2, 2, 1, 1, 1],
		[1, 1, 2, 1, 2],
		[2, 1, 2, 1, 1],
		[1, 2, 2, 1, 1],
		[1, 1, 1, 2, 2],
		[2, 1, 1, 2, 1],
		[1, 2, 1, 2, 1]
	];
	
	//--------------------------------------------------------------------------
	//
	//  Variables
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Overridden properties
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Properties
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Overridden methods
	//
	//--------------------------------------------------------------------------
	
    //----------------------------------
    //  encode
    //----------------------------------
	
	override protected function encode():void
	{
		bars = [];
		
		// start sequence
		bars.push(2, 1, 2, 1, 1, 1);
		
		var n:int = code.length;
		for (var i:int = 0; i < n; i++)
		{
			encodeDigit( parseInt( code.charAt(i) ) );
		}
		
		// end sequence
		bars.push(2, 1, 1, 1, 2);
	}
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
    //----------------------------------
    //  encodeDigit
    //----------------------------------
	
	private function encodeDigit(digit:int):void
	{
		if (digit < 0 || digit > 9)
			throw new ArgumentError("Code25 encodeDigit digit");
		
		for each (var b:int in DIGIT_ENCODING[digit])
		{
			bars.push(b, 1);
		}
	}
	
	//--------------------------------------------------------------------------
	//
	//  Overridden event handlers
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Event handlers
	//
	//--------------------------------------------------------------------------
	
}

}